package com.api.tournament.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.tournament.model.TournamentProfile;
import com.api.tournament.service.TournamentProfileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;

import static com.api.tournament.contonst.Const.TOURNAMENT_PROFILE_ID;


/**
* Created by wanghuiwen on 2021/03/24.
*/
@PowerEnable(name = "游戏配置",url = "/tournament/profile")
@Api(value = "游戏配置", tags = {"游戏配置"})
@RestController
@RequestMapping("/tournament/profile")
public class TournamentProfileController extends Ctrl{
    @Resource
    private TournamentProfileService tournamentProfileService;

    @ApiOperation(value = "游戏配置添加", tags = {"游戏配置"}, notes = "游戏配置添加")
    @PostMapping(value="/add",name="游戏配置添加")
    public Result add(@ApiParam TournamentProfile tournamentProfile) {
        TournamentProfile profile = tournamentProfileService.findById(TOURNAMENT_PROFILE_ID);
        if(profile !=null&& tournamentProfile.getId() == null){
            tournamentProfile.setId(TOURNAMENT_PROFILE_ID);
        }
        if(tournamentProfile.getId()!=null){
            tournamentProfileService.update(tournamentProfile);
        }else {
            tournamentProfileService.save(tournamentProfile);
        }
        return ResultGenerator.genSuccessResult(tournamentProfile);
    }

    @ApiOperation(value = "获取游戏配置", tags = {"游戏配置"}, notes = "获取游戏配置")
    @PostMapping(value="/detail",name="获取游戏配置")
    public Result add() {
        TournamentProfile profile = tournamentProfileService.findById(TOURNAMENT_PROFILE_ID);

        if (profile!=null){
            return ResultGenerator.genSuccessResult(profile);
        }else {
            return ResultGenerator.genSuccessResult();
        }
    }
}
